var app = getApp()
var util = require("../../../../utils/util.js")
// Page((a = {
Page({
  data: {
    targetIndex: 1,
    height: 40,
    oldHeight: 40,
    text: "",
    currentResult: 0,
    loadingBoo: !0,
    moreBoo: !0,
    list: [],
    discuss: 6,
    detailMsg: {
      mettingPush: {
        speed: 1
      },
      deptMarketingResources: {
        coverImg: 1,
        content: 1,
        contentType: 1,
        title: '宣传片',
        desc: '感冒是怎么来的'
      },

      doctorName: '小明',
      createTime: '2018-10-26'
    }
  },
  onLoad: function(options) {
    var that = this;
    var bgc = wx.getStorageSync('color')
    if (options.types == 0) {
      //获取医说详情
      var yisid = options.yisid
      app.util.request({
        'url': 'entry/wxapp/allyishuo',
        data: {
          yisid: yisid,
          op: 'xiangiqng'
        },
        success: function(res) {
          console.log(res)
          that.setData({
            h_text: res.data.data.h_text,
            zhuanjiainfo: res.data.data,
            yisid: yisid
          })
        }
      })
    }
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
  },
  onReady: function() {
    this.getZhuanjiaxiangqing()
  },
  onShow: function() {},
  onHide: function() {},
  bindlinechange: function(t) {
    t.detail.lineCount < 5 ? this.setData({
      heightFlag: !0
    }) : this.setData({
      heightFlag: !1
    });
  },
  sendBtn: function(e) {
    var that = this;
    var pingtext = that.data.text
    var time = util.formatTime(new Date());
    var yisid = that.data.yisid
    var openid = wx.getStorageSync('openid')
    var userInfo = wx.getStorageSync('userInfo')
    console.log(userInfo)
    var name = userInfo.nickName
    var touxiang = userInfo.avatarUrl
    var list = that.data.list
    //保存评论
    let obj = {
      name: name,
      createTime: time,
      pingtext: pingtext,
      touxiang: touxiang
    }
    list.push(obj);
    that.setData({
      list: list
    })
    app.util.request({
      'url': 'entry/wxapp/Savehuanjiaopl',
      data: {
        openid: openid,
        name: name,
        touxiang: touxiang,
        yisid: yisid,
        pingtext: pingtext,
        op: 'add'
      },
      success: function(res) {
        console.log(res)
      }
    })
  },
  getText: function(t) {
    this.setData({
      text: t.detail.value
    });
  },
  tapFun: function(t) {
    var yisid = this.data.yisid
    if (t.currentTarget.dataset.index == 2) {
      this.getAllpinglun(yisid)
    }
    t.currentTarget.dataset.index != this.data.targetIndex && this.setData({
      targetIndex: t.currentTarget.dataset.index
    });
  },
  getMore: function() {
    this.data.moreBoo && this.data.loadingBoo && (this.setData({
      loadingBoo: !1
    }), this.getComm());
  },
  getComm: function() {

  },
  getZhuanjiaxiangqing() {
    var that = this
    var id = that.data.zid
    var h_leixing = that.data.h_leixing
    if (h_leixing == 1) {
      app.util.request({
        'url': 'entry/wxapp/Zhuanjiaxiangqing',
        data: {
          id: id
        },
        success: function(res) {
          console.log(res)
          that.setData({
            zhuanjiainfo: res.data.data
          })
        }
      })
    }

  },
  gethjinfo: function(h_id, h_leixing) {
    var that = this
    app.util.request({
      'url': 'entry/wxapp/Allhjfenl',
      data: {
        h_id: h_id,
        h_leixing: h_leixing,
        op: 'post',

      },
      success: function(res) {
        console.log(res)
        var auth = res.data.auth
        that.setData({
          info: res.data,
          auth: auth
        })
      }
    })
  },
  getAllpinglun: function(yisid) {
    console.log(yisid)
    var that = this
    app.util.request({
      'url': 'entry/wxapp/Savehuanjiaopl',
      data: {
        yisid: yisid,
        op: 'all',
      },
      success: function(res) {
        console.log(res)
        that.setData({
          list: res.data
        })
      }
    })
  }
});